{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import os, sys\n",
    "sys.path += [\"../..\"]\n",
    "sys.path += [\"../../..\"]\n",
    "import torch\n",
    "import torch.functional as F\n",
    "from applications.DECA.interactive_deca_decoder import load_deca_and_data, test, plot_results\n",
    "from applications.DECA.optimize_latent_space import TargetEmotionCriterion, optimize\n",
    "import copy\n",
    "from gdl.layers.losses.EmoNetLoss import EmoNetLoss\n",
    "from gdl.models.DECA import DecaModule, DECA, DecaMode\n",
    "from skimage.io import imread\n",
    "import numpy as np\n",
    "from pathlib import Path\n",
    "import matplotlib.pyplot as plt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Loading the EmoNet model from /home/rdanecek/Workspace/Repos/emonet/pretrained/emonet_8.pth.\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/home/rdanecek/anaconda3/envs/work/lib/python3.6/site-packages/torch/nn/functional.py:3063: UserWarning: Default upsampling behavior when mode=bilinear is changed to align_corners=False since 0.4.0. Please specify align_corners=True if the old behavior is desired. See the documentation of nn.Upsample for details.\n",
      "  \"See the documentation of nn.Upsample for details.\".format(mode))\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Looking for checkpoint in '/home/rdanecek/Workspace/mount/scratch/rdanecek/emoca/finetune_deca/2021_03_08_22-30-55_VA_Set_videos_Train_Set_119-30-848x480.mp4CoPhotoCoLMK_IDW-0.15_Aug_early/detail/checkpoints'\n",
      "Found 4 checkpoints\n",
      " - /home/rdanecek/Workspace/mount/scratch/rdanecek/emoca/finetune_deca/2021_03_08_22-30-55_VA_Set_videos_Train_Set_119-30-848x480.mp4CoPhotoCoLMK_IDW-0.15_Aug_early/detail/checkpoints/deca-epoch=14-val_loss=0.9390.ckpt\n",
      " - /home/rdanecek/Workspace/mount/scratch/rdanecek/emoca/finetune_deca/2021_03_08_22-30-55_VA_Set_videos_Train_Set_119-30-848x480.mp4CoPhotoCoLMK_IDW-0.15_Aug_early/detail/checkpoints/deca-epoch=17-val_loss=0.9394.ckpt\n",
      " - /home/rdanecek/Workspace/mount/scratch/rdanecek/emoca/finetune_deca/2021_03_08_22-30-55_VA_Set_videos_Train_Set_119-30-848x480.mp4CoPhotoCoLMK_IDW-0.15_Aug_early/detail/checkpoints/deca-epoch=19-val_loss=0.9407.ckpt\n",
      " - /home/rdanecek/Workspace/mount/scratch/rdanecek/emoca/finetune_deca/2021_03_08_22-30-55_VA_Set_videos_Train_Set_119-30-848x480.mp4CoPhotoCoLMK_IDW-0.15_Aug_early/detail/checkpoints/last.ckpt\n",
      "Loading checkpoint '/home/rdanecek/Workspace/mount/scratch/rdanecek/emoca/finetune_deca/2021_03_08_22-30-55_VA_Set_videos_Train_Set_119-30-848x480.mp4CoPhotoCoLMK_IDW-0.15_Aug_early/detail/checkpoints/deca-epoch=14-val_loss=0.9390.ckpt'\n",
      "fc.weight  not available in reconstructed resnet\n",
      "fc.bias  not available in reconstructed resnet\n",
      "copy resnet state dict finished!\n",
      "creating the FLAME Decoder\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "../../models/DecaFLAME.py:92: UserWarning: To copy construct from a tensor, it is recommended to use sourceTensor.clone().detach() or sourceTensor.clone().detach().requires_grad_(True), rather than torch.tensor(sourceTensor).\n",
      "  torch.tensor(lmk_embeddings['dynamic_lmk_faces_idx'], dtype=torch.long))\n",
      "../../models/DecaFLAME.py:94: UserWarning: To copy construct from a tensor, it is recommended to use sourceTensor.clone().detach() or sourceTensor.clone().detach().requires_grad_(True), rather than torch.tensor(sourceTensor).\n",
      "  torch.tensor(lmk_embeddings['dynamic_lmk_bary_coords'], dtype=self.dtype))\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "fc.weight  not available in reconstructed resnet\n",
      "fc.bias  not available in reconstructed resnet\n",
      "copy resnet state dict finished!\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/home/rdanecek/anaconda3/envs/work/lib/python3.6/site-packages/pytorch3d/io/obj_io.py:457: UserWarning: Mtl file does not exist: /home/rdanecek/Workspace/mount/scratch/yfeng/Data/FLAME/geometry/template.mtl\n",
      "  warnings.warn(f\"Mtl file does not exist: {f}\")\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Loading the EmoNet model from /home/rdanecek/Workspace/Repos/emonet/pretrained/emonet_8.pth.\n",
      "DECA MODE RECONFIGURED TO: DecaMode.DETAIL\n",
      "DECA loaded\n",
      "The data will be loaded from: '/home/rdanecek/Workspace/mount/scratch/rdanecek/data/aff-wild2'\n",
      "The dataset is already processed. Loading\n",
      "Loading metadata of FaceVideoDataset from: '/home/rdanecek/Workspace/mount/scratch/rdanecek/data/aff-wild2/processed/processed_2021_Jan_19_20-25-10/metadata.pkl'\n",
      "Loading the dataset\n",
      "FaceVideoDataset already loaded.\n",
      "Dataset loaded\n",
      "Looking for video 148 in 477\n",
      "The dataset is already processed. Loading\n",
      "FaceVideoDataset already loaded.\n",
      "Loading the dataset\n",
      "FaceVideoDataset already loaded.\n",
      "Dataset loaded\n",
      "Found processed filelists in '/home/rdanecek/Workspace/mount/scratch/rdanecek/data/aff-wild2/processed/processed_2021_Jan_19_20-25-10/cache/47c56b8af9dcf6b425af013417cc6450'. Reprocessing will not be needed. Loading ...\n",
      "Loading done\n",
      "Dataset split found in: '/home/rdanecek/Workspace/mount/scratch/rdanecek/data/aff-wild2/processed/processed_2021_Jan_19_20-25-10/cache/tmp/07466c8e43171698637e87f596aeec86'. Loading ...\n",
      "Loading done\n",
      "Found processed filelists in '/home/rdanecek/Workspace/mount/scratch/rdanecek/data/aff-wild2/processed/processed_2021_Jan_19_20-25-10/cache/47c56b8af9dcf6b425af013417cc6450'. Reprocessing will not be needed. Loading ...\n",
      "Loading done\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/home/rdanecek/anaconda3/envs/work/lib/python3.6/site-packages/torch/nn/functional.py:3385: UserWarning: Default grid_sample and affine_grid behavior has changed to align_corners=False since 1.3.0. Please specify align_corners=True if the old behavior is desired. See the documentation of grid_sample for details.\n",
      "  warnings.warn(\"Default grid_sample and affine_grid behavior has changed \"\n"
     ]
    }
   ],
   "source": [
    "target_image = \"~/Workspace/mount/scratch/rdanecek/data/aff-wild2/processed/processed_2021_Jan_19_20-25-10/VA_Set/\" \\\n",
    "               \"detections/Train_Set/82-25-854x480/002400_000.png\"\n",
    "loss_to_use = TargetEmotionCriterion(target_image)\n",
    "path_to_models = '/home/rdanecek/Workspace/mount/scratch/rdanecek/emoca/finetune_deca'\n",
    "# run_name = '2021_03_01_11-31-57_VA_Set_videos_Train_Set_119-30-848x480.mp4_EmoNetLossB_F1F2VAECw-0.00150_CoSegmentGT_DeSegmentRend'\n",
    "run_name = '2021_03_08_22-30-55_VA_Set_videos_Train_Set_119-30-848x480.mp4CoPhotoCoLMK_IDW-0.15_Aug_early'\n",
    "stage = 'detail'\n",
    "relative_to_path = '/ps/scratch/'\n",
    "replace_root_path = '/home/rdanecek/Workspace/mount/scratch/'\n",
    "deca, dm = load_deca_and_data(path_to_models, run_name, stage, relative_to_path, replace_root_path)\n",
    "deca.deca.config.train_coarse = True\n",
    "deca.deca.config.mode = DecaMode.DETAIL\n",
    "# deca.deca.config.mode = DecaMode.COARSE\n",
    "image_index = 390 * 4 + 1\n",
    "values, visdict = test(deca, dm, image_index)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Looking for checkpoint in '/home/rdanecek/Workspace/mount/scratch/rdanecek/emoca/finetune_deca/2021_03_01_11-31-57_VA_Set_videos_Train_Set_119-30-848x480.mp4_EmoNetLossB_F1F2VAECw-0.00150_CoSegmentGT_DeSegmentRend/coarse/checkpoints'\n",
      "Found 3 checkpoints\n",
      " - /home/rdanecek/Workspace/mount/scratch/rdanecek/emoca/finetune_deca/2021_03_01_11-31-57_VA_Set_videos_Train_Set_119-30-848x480.mp4_EmoNetLossB_F1F2VAECw-0.00150_CoSegmentGT_DeSegmentRend/coarse/checkpoints/deca-epoch=03-val_loss=0.18.ckpt\n",
      " - /home/rdanecek/Workspace/mount/scratch/rdanecek/emoca/finetune_deca/2021_03_01_11-31-57_VA_Set_videos_Train_Set_119-30-848x480.mp4_EmoNetLossB_F1F2VAECw-0.00150_CoSegmentGT_DeSegmentRend/coarse/checkpoints/deca-epoch=04-val_loss=0.17.ckpt\n",
      " - /home/rdanecek/Workspace/mount/scratch/rdanecek/emoca/finetune_deca/2021_03_01_11-31-57_VA_Set_videos_Train_Set_119-30-848x480.mp4_EmoNetLossB_F1F2VAECw-0.00150_CoSegmentGT_DeSegmentRend/coarse/checkpoints/deca-epoch=09-val_loss=0.19.ckpt\n",
      "Loading checkpoint '/home/rdanecek/Workspace/mount/scratch/rdanecek/emoca/finetune_deca/2021_03_01_11-31-57_VA_Set_videos_Train_Set_119-30-848x480.mp4_EmoNetLossB_F1F2VAECw-0.00150_CoSegmentGT_DeSegmentRend/coarse/checkpoints/deca-epoch=03-val_loss=0.18.ckpt'\n",
      "fc.weight  not available in reconstructed resnet\n",
      "fc.bias  not available in reconstructed resnet\n",
      "copy resnet state dict finished!\n",
      "creating the FLAME Decoder\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "../../models/DecaFLAME.py:92: UserWarning: To copy construct from a tensor, it is recommended to use sourceTensor.clone().detach() or sourceTensor.clone().detach().requires_grad_(True), rather than torch.tensor(sourceTensor).\n",
      "  torch.tensor(lmk_embeddings['dynamic_lmk_faces_idx'], dtype=torch.long))\n",
      "../../models/DecaFLAME.py:94: UserWarning: To copy construct from a tensor, it is recommended to use sourceTensor.clone().detach() or sourceTensor.clone().detach().requires_grad_(True), rather than torch.tensor(sourceTensor).\n",
      "  torch.tensor(lmk_embeddings['dynamic_lmk_bary_coords'], dtype=self.dtype))\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "fc.weight  not available in reconstructed resnet\n",
      "fc.bias  not available in reconstructed resnet\n",
      "copy resnet state dict finished!\n",
      "Start training from scratch\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/home/rdanecek/anaconda3/envs/work/lib/python3.6/site-packages/pytorch3d/io/obj_io.py:457: UserWarning: Mtl file does not exist: /home/rdanecek/Workspace/mount/scratch/yfeng/Data/FLAME/geometry/template.mtl\n",
      "  warnings.warn(f\"Mtl file does not exist: {f}\")\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Adding EmoNet path '/home/rdanecek/Workspace/Repos/emonet'\n",
      "Loading the EmoNet model from /home/rdanecek/Workspace/Repos/emonet/pretrained/emonet_8.pth.\n",
      "Setting E_flame to eval\n",
      "Setting E_detail to eval\n",
      "Setting D_detail to eval\n",
      "DECA MODE RECONFIGURED TO: DecaMode.COARSE\n",
      "The data will be loaded from: '/home/rdanecek/Workspace/mount/scratch/rdanecek/data/aff-wild2'\n",
      "The dataset is already processed. Loading\n",
      "Loading metadata of FaceVideoDataset from: '/home/rdanecek/Workspace/mount/scratch/rdanecek/data/aff-wild2/processed/processed_2021_Jan_19_20-25-10/metadata.pkl'\n",
      "Loading the dataset\n",
      "FaceVideoDataset already loaded.\n",
      "Dataset loaded\n",
      "Looking for video 148 in 477\n",
      "The dataset is already processed. Loading\n",
      "FaceVideoDataset already loaded.\n",
      "Loading the dataset\n",
      "FaceVideoDataset already loaded.\n",
      "Dataset loaded\n",
      "Cached dataset not found in /home/rdanecek/Workspace/mount/scratch/rdanecek/data/aff-wild2/processed/processed_2021_Jan_19_20-25-10/cache/2d069c50223452b788c7c14f08e8a2184fb768f10c96da284deae4b8 and will have to be processed.\n",
      "Caching dataset to '/home/rdanecek/Workspace/mount/scratch/rdanecek/data/aff-wild2/processed/processed_2021_Jan_19_20-25-10/cache/e23da4d56ac01024e07103d9a4fcf329f6de789d4d8c1ca1a0159f85'\n",
      "Cached dataset not found in /home/rdanecek/Workspace/mount/scratch/rdanecek/data/aff-wild2/processed/processed_2021_Jan_19_20-25-10/cache/54ea0c29cd8ef702d3093a5bb824bafafc377ef717d51f77e115d2a7 and will have to be processed.\n",
      "Caching dataset to '/home/rdanecek/Workspace/mount/scratch/rdanecek/data/aff-wild2/processed/processed_2021_Jan_19_20-25-10/cache/e23da4d56ac01024e07103d9a4fcf329f6de789d4d8c1ca1a0159f85'\n",
      "Setting E_flame to eval\n",
      "Setting E_detail to eval\n",
      "Setting D_detail to eval\n",
      "DECA loaded\n"
     ]
    }
   ],
   "source": [
    "print(values.keys())\n",
    "plot_results(visdict, \"title\")\n",
    "optimize(deca, values, loss_to_use=loss_to_use)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "# %matplotlib notebook\n",
    "%matplotlib inline\n",
    "import matplotlib \n",
    "matplotlib.interactive(False)\n",
    "matplotlib.rcParams['figure.figsize'] = [20, 4]\n",
    "# wx, gtk, osx, tk, empty uses default\n",
    "# %matplotlib qt\n",
    "# %matplotlib notebook"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/home/rdanecek/anaconda3/envs/work/lib/python3.6/site-packages/torch/nn/functional.py:3063: UserWarning: Default upsampling behavior when mode=bilinear is changed to align_corners=False since 0.4.0. Please specify align_corners=True if the old behavior is desired. See the documentation of nn.Upsample for details.\n",
      "  \"See the documentation of nn.Upsample for details.\".format(mode))\n"
     ]
    }
   ],
   "source": [
    "image_index = 390*4 # big nose frown fail \n",
    "# image_index = 75*4\n",
    "# image_index = 9*4 +3\n",
    "values_fail, visdict_fail = test(deca, dm, image_index)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "tensor([[1.0523e+01, 5.2308e-03, 2.5351e-02]], device='cuda:0')"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#plot_results(visdict_fail, \"Fail\", plot_mode)\n",
    "values_fail['cam']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/home/rdanecek/anaconda3/envs/work/lib/python3.6/site-packages/torch/nn/functional.py:3063: UserWarning: Default upsampling behavior when mode=bilinear is changed to align_corners=False since 0.4.0. Please specify align_corners=True if the old behavior is desired. See the documentation of nn.Upsample for details.\n",
      "  \"See the documentation of nn.Upsample for details.\".format(mode))\n",
      "/home/rdanecek/anaconda3/envs/work/lib/python3.6/site-packages/torch/nn/functional.py:3385: UserWarning: Default grid_sample and affine_grid behavior has changed to align_corners=False since 1.3.0. Please specify align_corners=True if the old behavior is desired. See the documentation of grid_sample for details.\n",
      "  warnings.warn(\"Default grid_sample and affine_grid behavior has changed \"\n"
     ]
    }
   ],
   "source": [
    "image_index = 390*4 - 1\n",
    "values_before_fail, visdict_before_fail = test(deca, dm, image_index)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/home/rdanecek/anaconda3/envs/work/lib/python3.6/site-packages/torch/nn/functional.py:3063: UserWarning: Default upsampling behavior when mode=bilinear is changed to align_corners=False since 0.4.0. Please specify align_corners=True if the old behavior is desired. See the documentation of nn.Upsample for details.\n",
      "  \"See the documentation of nn.Upsample for details.\".format(mode))\n",
      "/home/rdanecek/anaconda3/envs/work/lib/python3.6/site-packages/torch/nn/functional.py:3385: UserWarning: Default grid_sample and affine_grid behavior has changed to align_corners=False since 1.3.0. Please specify align_corners=True if the old behavior is desired. See the documentation of grid_sample for details.\n",
      "  warnings.warn(\"Default grid_sample and affine_grid behavior has changed \"\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "tensor([[1.0696e+01, 5.2629e-03, 5.4284e-02]], device='cuda:0')"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "## FUNCTIONING IMAGE \n",
    "image_index = 0\n",
    "values_success, visdict_success = test(deca, dm, image_index)\n",
    "values_success['cam']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "ename": "SyntaxError",
     "evalue": "invalid syntax (<ipython-input-13-1260470546f5>, line 2)",
     "output_type": "error",
     "traceback": [
      "\u001b[0;36m  File \u001b[0;32m\"<ipython-input-13-1260470546f5>\"\u001b[0;36m, line \u001b[0;32m2\u001b[0m\n\u001b[0;31m    values_success['cam']\u001b[0m\n\u001b[0m                 ^\u001b[0m\n\u001b[0;31mSyntaxError\u001b[0m\u001b[0;31m:\u001b[0m invalid syntax\n"
     ]
    }
   ],
   "source": [
    "plot_results(visdict_success, \"Success\")\n",
    "values_success['cam']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/home/rdanecek/anaconda3/envs/work/lib/python3.6/site-packages/torch/nn/functional.py:3063: UserWarning: Default upsampling behavior when mode=bilinear is changed to align_corners=False since 0.4.0. Please specify align_corners=True if the old behavior is desired. See the documentation of nn.Upsample for details.\n",
      "  \"See the documentation of nn.Upsample for details.\".format(mode))\n",
      "/home/rdanecek/anaconda3/envs/work/lib/python3.6/site-packages/torch/nn/functional.py:3385: UserWarning: Default grid_sample and affine_grid behavior has changed to align_corners=False since 1.3.0. Please specify align_corners=True if the old behavior is desired. See the documentation of grid_sample for details.\n",
      "  warnings.warn(\"Default grid_sample and affine_grid behavior has changed \"\n"
     ]
    }
   ],
   "source": [
    "from copy import deepcopy \n",
    "values_replaced = deepcopy(values_fail)\n",
    "values_replaced['cam'] = deepcopy(values_before_fail['cam'])\n",
    "values_replaced, visdict_replaced = test(deca, dm, values=values_replaced)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "ename": "NameError",
     "evalue": "name 'values_replaced' is not defined",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mNameError\u001b[0m                                 Traceback (most recent call last)",
      "\u001b[0;32m<ipython-input-14-686990023675>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[1;32m      1\u001b[0m \u001b[0;31m#plot_results(visdict_replaced, \"Fail with successful camera\")\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 2\u001b[0;31m \u001b[0mvalues_replaced\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'cam'\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[0;31mNameError\u001b[0m: name 'values_replaced' is not defined"
     ]
    }
   ],
   "source": [
    "plot_results(visdict_replaced, \"Fail with successful camera\")\n",
    "values_replaced['cam']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/home/rdanecek/anaconda3/envs/work/lib/python3.6/site-packages/torch/nn/functional.py:3063: UserWarning: Default upsampling behavior when mode=bilinear is changed to align_corners=False since 0.4.0. Please specify align_corners=True if the old behavior is desired. See the documentation of nn.Upsample for details.\n",
      "  \"See the documentation of nn.Upsample for details.\".format(mode))\n",
      "/home/rdanecek/anaconda3/envs/work/lib/python3.6/site-packages/torch/nn/functional.py:3385: UserWarning: Default grid_sample and affine_grid behavior has changed to align_corners=False since 1.3.0. Please specify align_corners=True if the old behavior is desired. See the documentation of grid_sample for details.\n",
      "  warnings.warn(\"Default grid_sample and affine_grid behavior has changed \"\n"
     ]
    }
   ],
   "source": [
    "from copy import deepcopy \n",
    "values_replaced2 = deepcopy(values_before_fail)\n",
    "values_replaced2['cam'] = deepcopy(values_fail['cam'])\n",
    "\n",
    "values_replaced2, visdict_replaced2 = test(deca, dm, values=values_replaced2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "ename": "NameError",
     "evalue": "name 'values_replaced2' is not defined",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mNameError\u001b[0m                                 Traceback (most recent call last)",
      "\u001b[0;32m<ipython-input-15-c240123d3e9a>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[1;32m      1\u001b[0m \u001b[0;31m#plot_results(visdict_replaced2,  \"Success with failed camera\")\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 2\u001b[0;31m \u001b[0mvalues_replaced2\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'cam'\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[0;31mNameError\u001b[0m: name 'values_replaced2' is not defined"
     ]
    }
   ],
   "source": [
    "#plot_results(visdict_replaced2,  \"Success with failed camera\")\n",
    "values_replaced2['cam']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [],
   "source": [
    "#plot_results(visdict_success, \"Success example\")\n",
    "#plot_results(visdict_before_fail, \"Successful frame before fail\")\n",
    "#plot_results(visdict_fail, \"Fail\")\n",
    "#plot_results(visdict_replaced, \"Fail with successful camera\")\n",
    "#plot_results(visdict_replaced2, \"Success with failed camera\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.11"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
